package de.ifi.lmu.snitzelhunt.view;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import de.ifi.lmu.snitzelhunt.R;
import de.ifi.lmu.snitzelhunt.util.GSonUtility;
import de.ifi.lmu.snitzelhunt.util.basics.Ranking;

/**
 * 
 * @author Sarah
 *
 */
public class Activity_Ranking extends ActionBarActivity {

	
	private ListView rankingListView;
	private ArrayList<Ranking> tempRankList;
	private RankListViewAdapter raLiViewAd;
	private String[] rankinListToString;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_activity__ranking);

		Intent intent = getIntent();
		rankinListToString = intent.getStringArrayExtra("RANKING_LIST");
        tempRankList = new ArrayList<Ranking>();
		
		//prepare list
		rankingListView = (ListView) findViewById(R.id.currentRankingList);
		raLiViewAd = new RankListViewAdapter(this, tempRankList);
		rankingListView.setAdapter(raLiViewAd);
		  
		  for(int i=0; i<rankinListToString.length; i++)
		  {
			  tempRankList.add(GSonUtility.deserializeRanking(rankinListToString[i]));
		  }
		
		Log.i("list rank Gr��e", String.valueOf(tempRankList.size()));
		raLiViewAd.notifyDataSetChanged();
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity__ranking, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	
	/**
	 * If home button is clicked, kill intent and go to main screen
	 * @param view
	 */
	public void goHome(View view)
	{
		Intent returnToMainIntent = new Intent(this, MainActivity.class);
		returnToMainIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(returnToMainIntent);
	}

	

}
